Skip to content

pagination: fix panic when the last page link has page=0 - #1889

Open
AccursedGalaxy wants to merge 1 commit into
digitalocean:mainfrom
AccursedGalaxy:fix/pagination-zero-last-page
Open

pagination: fix panic when the last page link has page=0#1889
AccursedGalaxy wants to merge 1 commit into
digitalocean:mainfrom
AccursedGalaxy:fix/pagination-zero-last-page

Conversation

@AccursedGalaxy

Copy link
Copy Markdown

doctl gradient agent list panics on an account with no Gradient AI agents (#1888):

panic: runtime error: index out of range [0] with length 0
  do.(*paginatedList).set   do/pagination.go:41
  do.PaginateResp           do/pagination.go:68

The trace means lastPage() returned 0. PaginateResp allocated a zero-length page list and set(1, ...) indexed list[0]. The only way lastPage() returns 0 without an error is a links.pages.last URL whose page param parses to 0, which lines up with an empty collection (last = ceil(0/200) = 0). A last page below 1 is never valid whatever the server sends, so lastPage() clamps it to 1 and PaginateResp returns an empty list instead of panicking.

The regression test reproduces the reported panic and passes with the fix; go test ./do/ is green.

For transparency: I generated the patch with driver-os, a coding-agent harness I'm building. I wrote the regression test by hand first and confirmed it failed at base, and I reviewed the final diff myself.

Fixes #1888

lastPage() returned 0 when the links.pages.last URL had a page param
that parses to 0, so PaginateResp allocated a zero-length page list and
set(1, ...) panicked. A last page below 1 is never valid, so clamp it
to 1 and return an empty list instead.

Fixes digitalocean#1888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gradient agent list panics when the account has no agents

1 participant